﻿using MediatR;
using W.Product.API.Appliaction.Command.ProductCommand;
using W.Product.Repository.Interface;

namespace W.Product.API.Appliaction.CommandHandler.ProductCommandHandler
{
    public class ProductUpdateCommandHandler : IRequestHandler<ProductUpdateCommand, int>
    {
        private readonly IProductRepository _productRepository;

        public ProductUpdateCommandHandler(IProductRepository productRepository)
        {
            _productRepository = productRepository;
        }
        /// <summary>
        /// 产品管理修改
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public async Task<int> Handle(ProductUpdateCommand request, CancellationToken cancellationToken)
        {
            var list = await _productRepository.Update(new Domain.Product.ProductInfo()
            {
                ProductId = request.ProductId,
                ProductNo = request.ProductNo,
                ProductName = request.ProductName,
                ManuNo=request.ManuNo,
                InsideNo=request.InsideNo,
                UnitId=request.UnitId,
                ProductTypeId=request.ProductTypeId,
                GoOnline=request.GoOnline,
                Online=request.Online,
                ProductSpec=request.ProductSpec,
                ProductPrice=request.ProductPrice,
                WarehouseId=request.WarehouseId,
                BinLocationId=request.BinLocationId,
                ClientId=request.ClientId,
                ProductDesc=request.ProductDesc,
                ProductWrap="单包",
                ProductWeight="50g",
                UpdateName="admin",
                UpdateTime=DateTime.Now,
                CreateName="admin",
                CreateTime=request.CreateTime,
                DeleteName=request.DeleteName,
                DeleteTime=request.DeleteTime,
                IsDelete=false,
            });
            return list;
        }
    }
}
